package com.ruoyi.web.controller.durian;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.durian.domain.LlCoupon;
import com.ruoyi.durian.domain.LlThali;
import com.ruoyi.durian.service.LlCardPackageService;
import com.ruoyi.durian.service.LlCouponService;
import com.ruoyi.durian.service.LlThaliRecordService;
import com.ruoyi.durian.service.LlThaliService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 优惠券控制器
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/coupon")
public class CouponController extends BaseController {

    @Resource
    private LlCouponService llCouponService;

    @Resource
    private LlCardPackageService llCardPackageService;

    @Resource
    private LlThaliService llThaliService;

    @Resource
    private LlThaliRecordService llThaliRecordService;



    @GetMapping("/couponList")
    public TableDataInfo couponList(Integer status) {
        startPage();
        List<LlCoupon> llCouponList = llCouponService.selectList(status);
        return getDataTable(llCouponList);
    }
    /**
     * 优惠券详情
     *
     * @param id
     * @return
     */
    @GetMapping("/coupon/info/{id}")
    public AjaxResult couponInfo(@PathVariable Integer id) {
        return AjaxResult.success(llCouponService.getById(id));
    }

    /**
     * 失效券列表
     *
     * @param status
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo selectList(Integer status) {
        startPage();
        return getDataTable(llCardPackageService.selectList(status));
    }

    /**
     * 套餐列表
     *
     * @return
     */
    @ApiOperation("获取套餐列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "Integer", dataTypeClass = Integer.class),
    })
    @GetMapping("/thali/list")
    public TableDataInfo thailList(Integer status) {
        //初始化分页
        startPage();
        List<LlThali> thaliList = llThaliService.thailList(status);
        return getDataTable(thaliList);
    }
    /**
     * 套餐详情
     *
     * @return
     */
    @GetMapping("/thali/info/{id}")
    public AjaxResult thaliInfo(@PathVariable Integer id) {
        return llThaliService.thaliInfo(id);
    }

    /**
     * 套餐购买记录
     *
     * @return
     */
    @GetMapping("/thali/buy/list")
    public TableDataInfo thaliBuyList() {
        startPage();
        return getDataTable(llThaliRecordService.thaliBuyList());
    }

    /**
     * 购买套餐
     *
     * @return
     */
    @PostMapping("/thali/buy")
    public AjaxResult thaliBuy(Integer id) {
        return llThaliRecordService.thaliBuy(id);
    }

}
